package com.xpjhs.login.web.controller;

import javax.servlet.http.HttpServletRequest;





import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xpjhs.user.dao.UserDao;
import com.xpjhs.user.model.User;

@Controller
@RequestMapping
public class LoginController {

	@Autowired
	private UserDao userDao;

	@RequestMapping("/login")
	public String login() {
		return "login/login";
	}
  
	@RequestMapping(value = "/dologin")
	public String index(User user, HttpServletRequest request) {
		User user2 = userDao.findUserBy(user.getUsername(), user.getPassword());
		if (user2 == null) {
			request.setAttribute("error", "用户名或密码错误！！！");
			return "login/login";
		} else {
			request.getSession().setAttribute("user", user2);
			return "redirect:/index";
		}
	}	
	@RequestMapping("/index")
	public String index() {
		return "index";
	}
	

}
